Repository navigation
Add exercises to every chapter, expand core chapters, fix technical errors - #1
Merged
Merged
Conversation
…rcises The old chapter's Prim's code unpacked neighbour tuples in the wrong order, Kruskal referenced undefined names, the example diagram did not match its edge set, and topological sort silently returned partial orders on cyclic input. The chapter now covers edge lists and CSR, BFS path reconstruction, three-colour cycle detection, bipartiteness, Kahn and DFS topological sort, Kosaraju SCCs, the cut property, Bellman-Ford, a worked Dijkstra trace with why negative edges break it, a shortest-path selection table, historical context, and 8 exercises. Every Python block runs, and the algorithms were cross-checked against each other on random graphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Each chapter now ends with 5-8 exercises (traces, proofs, find-the-bug, implementations, design questions) graded by difficulty, with folded hints and worked solutions. Python in solutions was run with asserts. Writing the exercises surfaced real errors, fixed here, including: broken link-cut tree, wavelet tree kth and sparse table code (Ch 23); wrong succinct-space definitions and broken rank/find_close (Ch 24); red-black fix-up loop that never ran, wrong balance-factor signs (Ch 8); corrupt pairing heap and binomial-heap figures (Ch 9); B-tree insert losing the root (Ch 10); wrong struct size and invented overflow anecdotes (Ch 2); shunting-yard associativity (Ch 5); Cayley's formula (Ch 6); vEB layout example (Ch 16, 24); path-copying example and figure (Ch 17); OR-Set tombstones, version-vector concurrency, Paxos phases and quorum tolerance (Ch 27); BGP and TCAM descriptions and Space-Saving eviction (Ch 28); HNSW level sampling and shard remapping (Ch 30); Dynamo quorum condition and Spanner commit wait (Ch 31). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
check_book.py now requires an Exercises section in every chapter, checks exercise numbering, and checks the blank lines mdBook needs inside <details> blocks. Hints and solutions get a folded callout style and are expanded automatically when printing. Custom CSS font sizes switch from rem to em: mdBook's root font size is 62.5%, so the 'Where this connects' footer and figure captions were rendering at 9-11px. README, landing page and CONTRIBUTING describe the exercises. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
The Volume I-III overview pages were bare link lists (Volume II's was 25 words). Each now says what the volume is about, what to know before starting, what each chapter lets you do, and a suggested reading route. Chapter 11 gains a figure of the Dijkstra worked example with its shortest-path tree. Also removes a stray em-dash from Volume IV's note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Adds decrease-key via an indexed min-heap (with the lazy-deletion alternative used in Chapter 11), d-ary heaps and why d = 4 often wins, top-k, k-way merge and running median, Python heapq idioms, a heap sort trace, an array-to-tree index diagram and three exercises. Fixes the PriorityQueue example, which called undefined sift methods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Chapter 3 had no searching at all. Adds binary search with a half-open invariant (lower/upper bound, the midpoint overflow bug), binary search on the answer, two pointers, sliding windows, prefix sums as the inverse of difference arrays (including 2-D), and why arrays win on real caches. Chapter 4 adds in-place reversal, fast/slow pointers with a full argument for Floyd's cycle-start property (plus a diagram), merging with a dummy head, and merge sort on lists. Fixes a wrong claim that Lua tables are unrolled lists. Both chapters get three new exercises and added historical notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Chapter 7 was the thinnest chapter in the book. Adds a worked deletion trace, the expected height of random BSTs and the link to quicksort, successor/predecessor (with a diagram), floor/ceiling and range queries, BST validation (and the classic wrong version), order statistics via subtree sizes, and a historical context section. Chapter 6 adds iterative traversals with an explicit stack, the recursive tree-function pattern (height, size and diameter in one pass), rebuilding a tree from traversals and why preorder plus postorder is ambiguous, and serialization. Both chapters get new exercises; overlapping old exercises were reworked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
The chapter had no deletion at all. Adds single-pass top-down deletion covering every case (borrow, merge, predecessor/successor replacement, root shrink) with a worked example and a borrow-vs-merge diagram, what real databases do instead, a complete tested B-tree (search, insert, delete) with an invariant-checking random test, the height bound with a billion-key example, B+ tree range scans over leaf links, bulk loading, and two exercises. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Adds power-of-two-choices load balancing with seeded simulations of max load and of herding under stale load data, and where NGINX, HAProxy and Envoy use it. Adds eviction policies as data structures: O(1) LFU and LFU-DA, CLOCK, ARC and W-TinyLFU, with a comparison table and a seeded hit-rate simulation. Replaces the old LFU-D example, whose eviction could empty the whole cache and which did not implement dynamic aging. Three new exercises. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Exercises everywhere. Every one of the 31 chapters now ends with a graded exercise set (★ check, ★★ apply, ★★★ stretch). There are 225 exercises in total, each with a folded worked solution and, for the harder ones, a hint. Python in solutions was run with asserts. CI now checks that each chapter has an Exercises section, that exercises are numbered in order, and that the
<details>markup has the blank lines mdBook needs.Expanded chapters
Technical fixes found along the way (details in each commit message):
remagainst mdBook's 62.5% root size, so chapter footers and figure captions were rendering at 9-11px.Verification
python3 scripts/check_book.pypasses: all Python blocks parse, and every link and exercise block is well formed.mdbook buildemits no warnings.Generated by Claude Code